#include "junix.h"
using namespace std;

class B
{
	public:
		void f()
		{
			cout<<"B::f()"<<endl;
		}

		virtual void g()
		{
			cout<<"B::g()"<<endl;
		}
		int n;
	protected:
	private:
};

class D:public B
{
	public:
		void f()
		{
			cout<<"D::f()"<<endl;
		}

		virtual void g()
		{
			cout<<"D::g()"<<endl;
		}
	protected:
	private:
};

int main(int argc, char **argv)
{
	B b;
	b.f();
	cout<<endl;

	D d;
	d.f();
	d.B::f();
	cout<<endl;

	b.g();
	d.g();
	d.B::g();

	cout<<endl;
	B *pb = new D;
	pb->f();
	pb->g();
	pb->B::g();

	/*
	pb->D::g(); //error
	*/


	D* pd;
	try{
		pd = dynamic_cast<D*>(pb);
	}catch(bad_cast& e ){
		cout<<e.what()<<endl;
	}

	pd->g();
	pd->B::g();
	pd->D::g();

	cout<<endl;
//	b.D::f(); //error
    d.D::f();
}
